//
//  SearchedViewController.m
//  MonkeyTravel
//
//  Created by 刘珊珊 on 16/1/8.
//  Copyright © 2016年 WanWanSui. All rights reserved.
//

#import "SearchedViewController.h"
#import "sTravelViewController.h"
#import "sDestinationViewController.h"

@interface SearchedViewController ()<UISearchBarDelegate>
@property (nonatomic, strong) UIButton *sTravelButton;
@property (nonatomic, strong) UIButton *sDesButton;
@property (nonatomic, strong) UISearchBar *searchText;
@property (nonatomic, strong) UIView *upView;

@property (nonatomic, strong) sTravelViewController *sTController;
@property (nonatomic, strong) sDestinationViewController *sDController;

@end

@implementation SearchedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"%@", _string);
    [self createView];
    [self createChildController];
}

// 创建容器视图控制器
- (void) createChildController{
    // 游记
    self.sTController = [[sTravelViewController alloc]init];
    self.sTController.view.backgroundColor = [UIColor whiteColor];
    self.sTController.view.frame = CGRectMake(0, 40 * XHIGHT, WIDTH, HEIGHT - 40 * XHIGHT);
    
    // 旅行地
    self.sDController = [[sDestinationViewController alloc]init];
    self.sDController.view.backgroundColor = [UIColor whiteColor];
    self.sDController.view.frame = CGRectMake(0, 40 * XHIGHT, WIDTH, HEIGHT - 40 * XHIGHT);
    

    [self addChildViewController:self.sTController];
    [self.view addSubview:self.sTController.view];
    
    [self addChildViewController:self.sDController];
    [self.view addSubview:self.sDController.view];
}

// 创建view
- (void) createView{
    _upView = [[UIView alloc]initWithFrame:CGRectMake(10 * XWIDTH, 5 * XHIGHT, WIDTH - 20 * XWIDTH, 30 * XHIGHT)];
    _upView.backgroundColor = [UIColor colorWithRed:108 / 255.0 green:122 / 255.0 blue:137 / 255.0 alpha:0.3];
    _upView.layer.cornerRadius = (30 * XHIGHT) / 5;
    
    UIView *smallView = [[UIView alloc]initWithFrame:CGRectMake(2, 2, _upView.frame.size.width / 2 - 4, _upView.frame.size.height - 4)];
    smallView.backgroundColor = [UIColor whiteColor];
    smallView.layer.cornerRadius = (_upView.frame.size.height - 4) / 5;
    smallView.tag = 1101;
    [_upView addSubview:smallView];
    
    _sTravelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _sTravelButton.frame = CGRectMake(0, 0, _upView.frame.size.width / 2, _upView.frame.size.height);
    _sTravelButton.backgroundColor = [UIColor clearColor];
    [_sTravelButton setTitle:@"游记" forState:UIControlStateNormal];
    [_sTravelButton setFont:[UIFont systemFontOfSize:13]];
    [_sTravelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_sTravelButton addTarget:self action:@selector(sTravelButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [_upView addSubview:_sTravelButton];
    
    _sDesButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _sDesButton.frame = CGRectMake(_upView.frame.size.width / 2, 0, _upView.frame.size.width / 2, _upView.frame.size.height);
    _sDesButton.backgroundColor = [UIColor clearColor];
    [_sDesButton setTitle:@"旅游地" forState:UIControlStateNormal];
    [_sDesButton setFont:[UIFont systemFontOfSize:13]];
    [_sDesButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_sDesButton addTarget:self action:@selector(sDesButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [_upView addSubview:_sDesButton];
    
    [self.view addSubview:_upView];
}

// button点击事件
- (void)sTravelButtonDidPress:(UIButton *)sender{
    UIView *view = [self.view viewWithTag:1101];
    
    // 动画
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionRepeat animations:^{
        [UIView setAnimationRepeatCount:1];
        view.frame = CGRectMake(2, 2, _upView.frame.size.width / 2 - 4, _upView.frame.size.height - 4);
    } completion:^(BOOL finished) {
    }];
    
    // 容器视图控制器push方法
    [self transitionFromViewController:_sDController toViewController:_sTController duration:1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
    } completion:^(BOOL finished) {
    }];
}

- (void)sDesButtonDidPress:(UIButton *)sender{
    UIView *view = [self.view viewWithTag:1101];
    
    // 动画
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionRepeat animations:^{
        [UIView setAnimationRepeatCount:1];
        view.frame = CGRectMake(_upView.frame.size.width / 2 + 2, 2, _upView.frame.size.width / 2 - 4, _upView.frame.size.height - 4);
    } completion:^(BOOL finished) {
    }];
    
    // 容器视图控制器push方法
    [self transitionFromViewController:_sTController toViewController:_sDController duration:1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
    } completion:^(BOOL finished) {
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
